package sb.mybatisp.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;
import sb.mybatisp.pojo.User;
import sb.mybatisp.pojo.UserAndCourseOutDTO;

import java.util.List;

@Repository
@Mapper
public interface UserMapper extends BaseMapper<User> {

    @Select("select name,age,email mail from user where age>#{age}")
    List<User> selectByAge(int age);

    @Select("select user.*,user.id as uid,user.name as uname,course.*,course.id as cid, course.name as cname from user left join course on user.id=course.user_id")
    List<UserAndCourseOutDTO> selectUserAndCourse();

    @Select("select user.*,user.id as uid,user.name as uname,course.*,course.id as cid, course.name as cname from user right join course on user.id=course.user_id")
    Page<UserAndCourseOutDTO> selectUserAndCoursePage(Page page);


    /**=============xml=============*/
    List<User> allUser();
}
